import React, { Component, useMemo } from "react";
import { View, Image, Text, Button } from "@tarojs/components";
import Taro from "@tarojs/taro";

import styles from "./index.module.scss";
import MiniHeader from "@/components/UI/MiniHeader";
import cn from "@/utils/classnames";
import API from "@/api";
import useThrottleFn from "ahooks/lib/useThrottleFn";

export default function() {
  let { run } = useThrottleFn(e => {
    if (e.detail.errMsg.includes("fail")) {
      Taro.showToast({
        title: "获取授权失败",
        icon: "none",
      });
    } else {
    }
    let { userInfo } = e.detail;
    API.Login.officialLogin({
      headUrl: userInfo.avatarUrl,
      nickname: userInfo.nickName,
      sex: userInfo.gender,
    });
  });
  return (
    <View className={styles.page}>
      {/* < MiniHeader title="教育" transparent hideHome></> */}
      <Image
        className={styles.logo}
        src="http://qihs5ygb9.hb-bkt.clouddn.com/mini/%E7%BC%96%E7%BB%84%203_slices/%E7%BC%96%E7%BB%84%203@2x.png"
      ></Image>
      <Button className={cn(styles.btn, "flex-center")} openType="getUserInfo" onGetUserInfo={run}>
        <Image
          className={styles.wx}
          src="http://qihs5ygb9.hb-bkt.clouddn.com/mini/%E7%BC%96%E7%BB%84%203_slices/weixin@2x.png"
        ></Image>
        微信授权
      </Button>
    </View>
  );
}
